/*Generate Figures in the main text and the appendix*/
clear all
set more off
global processed_data        "${rootdir}\processed_data"
global density_data_dir      "${rootdir}\results\density\bin_data"
global density_graph_dir     "${rootdir}\results\density\bunching_figs"
global density_mse_dir       "${rootdir}\results\density\mse"
global causal_data_dir       "${rootdir}\results\causal\reg_data"  
global causal_temp_dir       "${rootdir}\results\causal\reg_data\temp"  
global causal_bt_dir         "${rootdir}\results\causal\bootstrap" 
global causal_ITT_dir        "${rootdir}\results\causal\TE"  
global causal_graph_dir      "${rootdir}\results\causal\outcome_figs"
cd "${rootdir}\code"
qui run "${rootdir}\code\sub_create.do"
qui run "${rootdir}\code\sub_density_nonparametric.do"
qui run "${rootdir}\code\sub_density_parametric_compute.do"
qui run "${rootdir}\code\sub_figure_chen.do"
qui run "${rootdir}\code\sub_causal.do" 
qui run "${rootdir}\code\sub_causal_2sls.do" 
qui run "${rootdir}\code\sub_causal_figure.do" 
qui run "${rootdir}\code\notch_mse_roundq.ado"
qui run "${rootdir}\code\notch_ct_roundq.ado"
qui run "${rootdir}\code\notch_fie_ct_roundq.ado"


/******Figure 2*******/
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42"  
global name            "East_Manuf"
global location        "East"
global firm            "domestic"   
global firm_name       "Domestic-Owned" //
global year_condition  "year==2002"
global year_name       "2002"
global year_note       "in 2002"
if "${firm}"=="domestic"  {
global cutoff_note     "(cutoff=300)"
}
qui density_data
qui density_fig_c300





 
/******Figure A2*******/
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42"  
global name            "East_Manuf"
global location        "East"
global firm            "domestic"   
global firm_name       "Domestic-Owned" //
 
*panel (a)
global year_condition  "year==2000"
global year_name       "2000"
global year_note       "in 2000"
if "$firm"=="domestic"{
global cutoff_note     "(cutoff=500 for SOE, =850 for private)"
}
qui density_data
qui density_fig_c300


*panel (b)
global year_condition  "year==2001"
global year_name       "2001"
global year_note       "in 2001"
if "$firm"=="domestic"{
global cutoff_note     "(cutoff=300 since July)"
}
qui density_data
qui density_fig_c300




/******Figures 3 & A6*******/
//East
global name            "East_Manuf"
global location        "East"
global firm            "domestic" //  
global firm_name       "Domestic-Owned" //  
global year_name       "2002"
global year_note      "in 2002"
global cutoff_note    "(cutoff=300)"
global cutoff=300


*panel (a) & (b) of Figures 3 
global year_name_ct    "2000"
global name_ct         "East_Manuf"
if $cutoff == 300 & "${firm}"=="domestic" {
global low=-80
global high=10
}
qui DD_density
qui DD_density_fig  
qui DD_density_diff


*panel (c) & (d) of Figures 3 and panel (a) of Figure A6 
clear mata
set matsize 6000
set seed 1234
set trace off
set tracedepth 1
global nboot=500
global density        "DP_q"  
qui do "${rootdir}\code\sub_density_parametric_search.do"
global degree=5
global low=-70
global high=10
density_parametric_compute  
density_parametric_fig  
density_parametric_exfig  




 




/******Figure A4******/
global condition       "group==2 & cic_adj2>=13 & cic_adj2<=42"   
global name            "CW_Manuf"
global location        "Central & West"
global firm            "domestic" 
global firm_name        "Domestic-Owned" 
global cutoff=200
global year_condition  "year==2002"
global year_name       "2002"
density_data
global year_condition  "year==2000"
global year_name       "2000"
density_data
global year_name       "2002"
global year_note      "in 2002"
global cutoff_note    "(cutoff=200)"
global name_ct         "CW_Manuf"
global year_name_ct    "2000"
global low =-30 
global high=10
qui DD_density
qui DD_density_fig





/******Figure A5******/
global condition       "group==3 & cic_adj2>=13 & cic_adj2<=42"
global name            "ME_Manuf"
global location        "of Machinery & Electronic"
global firm            "domestic"
global firm_name       "Domestic-Owned"
global cutoff=100
global year_condition  "year==2002"
global year_name       "2002"
qui density_data
global year_condition  "year==2000"
global year_name       "2000"
qui density_data
global year_name       "2002"
global year_note       "in 2002"
global cutoff_note     "(cutoff=100)"
global name_ct         "ME_Manuf"
global year_name_ct    "2000"
global low =-30 
global high=10
qui DD_density
qui DD_density_fig 




/******Figures A6******/
global cutoff=300 
set seed 1234
set trace off
set tracedepth 1
global nboot=300
global density        "DP_q"  
set matsize 6000


**panel (b)
global condition       "group==2 & cic_adj2>=13 & cic_adj2<=42"   
global name            "CW_Manuf"
global location        "Central & West"
global firm            "domestic"
global firm_name       "Domestic-Owned"
global year_condition  "year==2002"
global year_name       "2002"
global year_note        "in 2002"
global cutoff_note    "(cutoff=200)"
qui density_data
global degree=5
global low=-70
global high=10
density_parametric_compute  
density_parametric_exfig  



**panel (c)
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42"   
global name            "East_Manuf"
global location        "East"
global firm            "domestic"
global firm_name       "Domestic-Owned"
global year_condition  "year==2000"
global year_name       "2000"
global year_note        "in 2000"
global cutoff_note    "(cutoff=500 for SOE, =850 for PIE)"
qui density_data
global degree=5
global low=-70
global high=10
density_parametric_compute  
density_parametric_exfig  



**panel (d)
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42" 
global name            "East_Manuf"
global location        "East"
global firm            "foreign"
global firm_name       "Foreign-Invested"
global year_condition  "year==2002"
global year_name       "2002"
global year_note        "in 2002"
global cutoff_note    "(no cutoff)"
qui density_data
global degree=5
global low=-70
global high=10
qui do "${rootdir}\code\sub_density_parametric_compute_fie.do"
 


 

/******Figures 5 & 6******/ 
global draw_fig         =0
global nboot            =500
global run_bootstrap    =0
global draw_fig         =1
global reg_degree       "2nd"          
global fe_status        "fe"            
global bs_method        "bparametric"   
global density          "DP_q"  
 
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42 "  
global name            "East_Manuf"
global location        "East"
global firm            "domestic"  
global firm_name       "Domestic-Owned"
global year_condition  "year==2002"
global year_name       "2002"
global year_note       "in 2002"
global cutoff = 300
global cutoff_note_rv     "(Cutoff=300 during Jul 2001~Sep 2003)"
global cutoff_note     "(cutoff=300)"
global degree=5
global low=-70  
global high=10
global graph_low=$cutoff + $low
global graph_high=$cutoff + $high

**Figure 5
global winsor=0    
global trim=1      
global myvar  "trade_custom" 
global myvar_name "Trade Participation"
**panel (a)
qui fig_0200

**panel (b)
qui fig_1year

**panel (c)
qui causal_est


**Figure 6
global winsor=1 
global trim=0
global myvar_name "Productivity"
global myvar "tfpq"
**panel (a)
qui fig_020400

**panel (b)
qui fig_1year

**panel (c)
qui causal_est


 
 



/******Figure A3******/
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42 & age>1 & age~=."
global name            "East_exist_Manuf"
global location        "East (Existing)"
global firm            "domestic" 
global firm_name       "Domestic-Owned"
global cutoff=300
global year_name       "2002"
global year_condition  "year==2002"
qui density_data
global year_name       "2000"
global year_condition  "year==2000"
qui density_data
global year_name       "2002"
global year_note      "in 2002"
global cutoff_note    "(cutoff=300)"
global year_name_ct    "2000"
global name_ct         "East_Manuf"
global low=-80
global high=10
qui DD_density
qui DD_density_fig 




/******Figure A7******/
global condition       "group==1 & cic_adj2>=13 & cic_adj2<=42 "  
global name            "East_Manuf"
global location        "East"
global firm            "domestic"  
global firm_name       "Domestic-Owned"
global year_condition  "year==2002"
global year_name       "2002"
global year_note       "in 2002"
global cutoff=300
global cutoff_note     "(cutoff=300)"

global myvar  "F318"
global myvar_name "Total Asset"
qui figure_chen 

global myvar  "F322"
global myvar_name "Total Debt"
qui figure_chen 

global myvar  "F323"
global myvar_name "Equity"
qui figure_chen 